package com.zjpavt.client.extenddevice.infrared;

import com.zjpavt.client.enums.ExtendDeviceEnum;
import com.zjpavt.client.extenddevice.AbstractExtendDevice;
import com.zjpavt.client.extenddevice.IExtendDevice;
import com.zjpavt.client.nativemethod.JnIMethod;

/**
 * 红外模块
 * @author zyc
 */
public class InfraredModule extends AbstractExtendDevice implements IExtendDevice {
    public static final String TURN_ON = "OPEN";
    public static final String TURN_OFF = "CLOSE";
    public static final String LEARN = "LEARN";
    public static final String TEACH = "TEACH";

    /**
     * 红外模块
     * @param extendNum
     */
    public InfraredModule(int extendNum) {
        super(extendNum, ExtendDeviceEnum.INFRARED_MODULE);
    }

    public void learnOpen() {
        sendCommand(LEARN,true);
    }

    public void learnClose() {
        sendCommand(LEARN,false);
    }

    public void teachOpen() {
        sendCommand(TEACH,true);
    }

    public void teachClose() {
        sendCommand(TEACH,false);
    }

    private void sendCommand(String learnOrTeach,boolean isOpen) {
        String command;
        if (isOpen) {
            command = "<AT_" + learnOrTeach +"_" + TURN_ON + ">";
        } else {
            command = "<AT_" + learnOrTeach + "_" + TURN_OFF + ">";
        }
        JnIMethod.sendMessage2ExtendDeviceByRs485(115200,getExtendNum(),command,200);
    }
}
